package com.wk1un2.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.wk1un2.entity.Track;
import com.wk1un2.service.TrackService;
import com.wk1un2.util.Result;

@RequestMapping("/public")
@RestController
public class TrackController {
	@Autowired
	private TrackService trackservice;

	@RequestMapping("/getAllTrack")
	public Object getAll(@RequestParam Map<String, Object> map, Integer page, Integer limit) {
		//Integer page = Integer.parseInt(map.get("page").toString());
		//Integer limit = Integer.parseInt(map.get("limit").toString());
		map.put("page", (page - 1) * limit);
		map.put("limit", limit);
		Result res = new Result(0, "success", trackservice.count(map), trackservice.getAll(map));
		return res;
	}

	
	@RequestMapping("/getBystuid")
	public Object getBystuid(@RequestParam Map<String, Object> map, Integer page, Integer limit) {
		map.put("page", (page - 1) * limit);
		map.put("limit", limit);
		Result res = new Result(0, "success", trackservice.getBystuid(map).size(), trackservice.getBystuid(map));
		return res;
	}
	
	@RequestMapping("/addTrack")
	public Result insert(Track track) {
		Result res = new Result(0, "添加成功", trackservice.insert(track), true);
		return res;
	}
	
	@RequestMapping("/updateTrack")
	public Result updateById(Track track,String trackstate2) {
		
		if (!trackstate2.equals(null)) {
			if (trackstate2.equals("已完成")) {
				track.setTrackstate(1);
			}else if (trackstate2.equals("未完成")) {
				track.setTrackstate(3);
			}else if (trackstate2.equals("跟进中")) {
				track.setTrackstate(2);
			}
		}
		
		Result res = new Result(0, "修改成功", trackservice.update(track), true);
		return res;
	}
	@RequestMapping("/deleteTrack")
	public Result deleteById(Integer trackid) {
		Result res = new Result(0, "删除成功", trackservice.delete(trackid), true);
		return res;
	}
	
	
}
